import jwt
import logging

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger()


def decode_jwt(token):
    # Decode the JWT token
    decoded_jwt = jwt.decode(token, options={"verify_signature": False})
    return dict(decoded_jwt)


if __name__ == "__main__":
    try:
        access_token = input("请输入你要解析的JWT Token!并按Enter继续:\n")
        if "Bearer " in access_token:
            access_token = access_token.replace("Bearer ", "")
        username = decode_jwt(access_token).get("username")
        logger.info(f"解析出来的username:{username}")
    except Exception as e:
        logger.exception(f"解析JWT Token出错:{e}")